package com.ehsunbehravesh.service.security.ejb.encryption;

import java.security.Key;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.interfaces.RSAKey;
import javax.crypto.SecretKey;

/**
 * Encryption business base interface.
 *
 * @author ehsun.behravesh
 */
public interface EncryptionBusiness {

  /**
   * RSA Encryption
   *
   * @param key
   * @param data
   * @return
   * @throws IllegalArgumentException
   */
  public byte[] encryptRSA(final Key key, final byte[] data) throws EncryptionServiceException;
  
  /**
   * 
   * @param key
   * @param data
   * @return
   * @throws EncryptionServiceException 
   */
  public byte[] encryptRSABlock(final Key key, final byte[] data, final int keySize) throws EncryptionServiceException;

  /**
   * RSA Decryption
   *
   * @param key
   * @param encrypted
   * @return
   * @throws IllegalArgumentException
   */
  public byte[] decryptRSA(final Key key, final byte[] encrypted) throws EncryptionServiceException;

  /**
   * 
   * @param key
   * @param encrypted
   * @return
   * @throws EncryptionServiceException 
   */
  public byte[] decryptRSABlock(final Key key, final byte[] encrypted, final int keySizes) throws EncryptionServiceException;
  
  /**
   * AES Encryption
   *
   * @param key
   * @param data
   * @return
   * @throws IllegalArgumentException
   */
  public byte[] encryptAES(final byte[] key, final byte[] data) throws EncryptionServiceException;

  /**
   * AES Decryption
   *
   * @param key
   * @param encrypted
   * @return
   * @throws IllegalArgumentException
   */
  public byte[] decryptAES(final byte[] key, final byte[] encrypted) throws EncryptionServiceException;

  /**
   * RSA KeyPair Generator
   *
   * @return
   */
  public KeyPair generateRSAKeyPair(final int size);

  /**
   * Creates RSA PublicKey out of byte array
   *
   * @param key
   * @return
   * @throws IllegalArgumentException
   */
  public PublicKey createRSAPublicKey(final byte[] key) throws EncryptionServiceException;

  /**
   * Creates RSA PrivateKey out of byte array
   *
   * @param key
   * @return
   * @throws IllegalArgumentException
   */
  public PrivateKey createRSAPrivateKey(final byte[] key) throws EncryptionServiceException;
  
  /**
   * Generate new AES key (128, 192, 256)
   * @param bits
   * @return
   * @throws EncryptionServiceException 
   */
  public SecretKey generateAESKey(final int bits) throws EncryptionServiceException;
  
  /**
   * 
   * @param key
   * @return 
   */
  public int getRSAKeySize(RSAKey key);      
  /**
   * 
   * @param bits
   * @return
   * @throws EncryptionServiceException 
   */
  public SecretKey generateBlowfishKey(final int bits) throws EncryptionServiceException;
  
  /**
   * 
   * @param key
   * @param data
   * @return
   * @throws EncryptionServiceException 
   */
  public byte[] encryptBlowfish(final byte[] key, final byte[] data) throws EncryptionServiceException;

  /**
   * 
   * @param key
   * @param encrypted
   * @return
   * @throws EncryptionServiceException 
   */
  public byte[] decryptBlowfish(final byte[] key, final byte[] encrypted) throws EncryptionServiceException;

}
